//
//  BaseTableViewController.swift
//  weibo
//
//  Created by Fosen on 15/11/27.
//  Copyright © 2015年 fosen. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {

    
    //添加一个 用户是否登录的标记
    var userLogin = UserAccountViewModel().userLogin
    //给BaseVc添加访客视图属性
    var visitorView : VisitorLoginView?
    //loadview 准备视图层次结构  加载视图
    //苹果专门为手写代码准备了方法  一旦实现了该方法 sb/xib  就会自动失效
    //在loadview中 会自动检测 根视图是否为空  如果为空  会自动调用loadView
    
    override func loadView() {
        //自定义视图
//        if userLogin {
//            super.loadView()
//        }
//        setVisitorView()

        userLogin ? super.loadView() : setVisitorView()
    }
    
    
    private func setVisitorView (){
    
        visitorView = VisitorLoginView()
        visitorView?.visitorLoginViewDelegate = self
        view = visitorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userwillRegister")

    }
    
    
    @objc func userWillLogin() {
        
        let oauthVc = OAuthViewController()
        let nav = UINavigationController (rootViewController: oauthVc)
        presentViewController(nav, animated: true,completion: nil)
        
    }
    
    @objc func userwillRegister() {
        
        print(__FUNCTION__)

    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }


}

//static dispatch_once_t onceToken;
//      dispatch_once(&onceToken,{
//
//
//});
